package com.niu.online.controller;


import com.niu.business.constent.Constant;
import com.niu.business.model.entity.SysUser;
import com.niu.business.model.mapper.SysUserMapper;
import com.niu.business.utils.Aobject;
import com.niu.business.utils.Bobject;
import com.niu.business.utils.BusiUtils;
import com.niu.business.utils.BusiUtilsException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author xmx
 * @since 2022-03-22
 */
@Controller
@RequestMapping("/sysUser")
public class SysUserController {
    @Resource
    private SysUserMapper mapper;
    @Resource
    private Aobject aobject;
    @Resource
    private Bobject bobject;
    @Resource
    private BusiUtils busiUtils;

    @RequestMapping("/insert")
    public void insertUser() {
//        userService.insertUser();
    }

    @RequestMapping("/select")
    public void selectOne() {
        SysUser sysUser = mapper.selectById(1);
        System.out.println(sysUser.toString() + "[]123");
    }

    @RequestMapping("/ceshi")
    public void ceshi() {
        aobject.toSay();
    }

    @RequestMapping("/login")
    public void login(@RequestBody SysUser sysUserIn) throws Exception {
        SysUser sysUser1 = mapper.selectByUserName(sysUserIn);
        if (sysUser1 != null && sysUser1.getUserPassword().equals(sysUserIn.getUserPassword())) {
            if (!sysUser1.getUserType().equals("F")) {
                sysUser1.setUserType(Constant.ONLINE_TYPE);
                sysUser1.setUserUpdateTime(new Date());
                mapper.updateById(sysUser1);

            } else {
                throw BusiUtilsException.createException("用户被禁用");
            }
        } else {
            throw BusiUtilsException.createException("用户不存在");
        }
    }


}

